<template>
  <div class="cartcontrol">
    <transition name="move">
      <div class="cart-decrease" v-show="food.count> 0" @click.stop.prevent="desccart">
        <span class="inner">-</span>
      </div>
    </transition>
    <div class="cart-count" v-show="food.count > 0">{{food.count}}</div>
    <div class="cart-add" @click.stop.prevent="addcart">+</div>
  </div>
</template>

<script>
import Vue from 'vue'
export default {
  name: 'Cartcontrol',
  props: {
    food: {
      type: Object
    }
  },
  methods: {
    addcart () {
      if (!this.food.count) {
        Vue.set(this.food, 'count', 1)
        this.food.count = 1
      } else {
        this.food.count += 1
      }
      this.$emit('cartadd', event.target)
    },
    desccart () {
      if (!this.food.count) {
        Vue.set(this.food, 'count', 1)
        this.food.count = 1
      } else {
        this.food.count -= 1
      }
    }
  }
}
</script>

<style lang="stylus" scoped>
  .cartcontrol
    font-size 0
    .cart-decrease
      display inline-block
      padding .12rem
      transition all 0.4s linear
      &.move-transition
        opacity 1
        transform translate3d(0,0,0)
        .inner
          transform  rotate(0)
      .inner
        display inline-block
        line-height .48rem
        font-size .48rem
        color rgb(0,160,220)
        transition all 0.4s linear
      &.move-enter, &.move-leave
        opacity 0
        transform translate3d(24px,0,0)
        .inner
          transform  rotate(180deg)
    .cart-count
      font-size .2rem
      vertical-align top
      width .24rem
      padding-top .12rem
      line-height .48rem
      text-align center
      font-size .2rem
      color rbg(147,153,159)
      display inline-block
    .cart-add
      display inline-block
      padding .12rem
      line-height .48rem
      font-size .48rem
      color rgb(0,160,220)
</style>
